package com.lovo.controller;

import com.lovo.model.DTO.UserDTO;
import com.lovo.result.ResponseResult;
import com.lovo.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@ResponseResult
@RequestMapping("/users")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Object findByNameAndPwd(HttpServletRequest request, @RequestBody UserDTO userDTO) {
        userDTO = userService.findByNameAndPwd(userDTO.getName(), userDTO.getPwd());
        request.getSession().setAttribute("user", userDTO);
        return userDTO;
    }

    ;

    @PostMapping
    public Object add(@RequestBody UserDTO userDTO) {
        userService.save(userDTO);
        return null;
    }
}
